<template>
<div class="bind-msg">
  <div class="top">
    <div class="top-left" @click.stop="$emit('back')"><span class="V7_iconfont V7_iconV7tubiao_mianfanhui"></span>返回</div>
    <div v-if="active !== 3">
      <div class="el-steps el-steps--horizontal">
        <div v-for="item in steps" :key="item.num" class="el-step is-horizontal" style="flex-basis: 200px; margin-right: 0px;">
          <div class="el-step__head" :class="active === item.num ? 'is-process' : ''">
            <div class="el-step__line" style="margin-right: 0px;"></div>
            <div class="el-step__icon is-text">
              <div class="el-step__icon-inner">{{item.num + 1}}</div>
            </div>
            <div class="step-title">{{item.title}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <companyMsg ref="companyMsg" :message="message" @next="active = active + 1" v-if="active === 0"></companyMsg>
  <codeCom ref="codeCom" v-if="active === 1" @changeMsg="changeMsg" :message="message" @next="active = active + 1" @isDisabled="changeDisabled"></codeCom>
  <appMsg ref="appMsgRef" v-if="active === 2" :message="message" @next="$emit('finish')"></appMsg>
  <addressCom ref="addressRef" v-if="active === 3"></addressCom>
  <div style="margin-top: 50px;text-align: center;margin-bottom: 24px" v-if="active !== 3">
    <el-button size="mini" @click="active = active - 1" v-if="active !== 0">上一步</el-button>
    <el-button type="primary" size="mini" @click="nextClick" v-if="active !== 2" :disabled="active === 1 && isDisabled">下一步</el-button>
    <el-button type="primary" size="mini" @click="nextClick" v-if="active === 2">完成</el-button>
  </div>
</div>
</template>

<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator'
import addressCom from './components/address.vue'
import appMsg from './components/appMsg.vue'
import codeCom from './components/codeCom.vue'
import companyMsg from './components/companyMsg.vue'
@Component({
  name: 'BindMsg',
  components: {
    companyMsg,
    addressCom,
    appMsg,
    codeCom
  }
})
export default class BindMsg extends Vue {
  @Prop({ default: () => ({}) }) private message!: any;
  private active = 0
  private isDisabled = false
  private steps = Object.freeze([
    { title: '企业信息录入', num: 0 },
    { title: '扫码授权', num: 1 },
    { title: '应用信息录入', num: 2 }
  ])

  private changeDisabled (val: boolean) {
    this.isDisabled = val
  }

  public changeStep (step) {
    this.active = step
  }

  private changeMsg (data: any) {
    this.$emit('changeMsg', data)
  }

  private nextClick () {
    if (this.active === 2) {
      (this.$refs as any).appMsgRef.save()
    } else if (this.active === 1) {
      this.active = 2
    } else if (this.active === 0) {
      (this.$refs as any).companyMsg.save()
    }
  }
}
</script>
<style lang="stylus" scoped>
.top
  display: inline-block;
  font-size: 14px;
  line-height: 14px;
  font-weight: bold;
  width: 100%;
  height: 56px;
  background: #fff;
  border-radius: 10px 10px 0px 0px;
  box-shadow: rgb(224 230 240) 0px 1px 4px 0px;
  padding: 20px 24px;
  .top-left
    font-weight: 600;
    cursor pointer
    color: #303753;
    font-size: 14px
    float: left;
    margin-right: 100px;
    line-height: 24px;
  .V7_iconfont
    color: #C4CDD4;
    margin-right: 8px;
    font-size: 14px;
.el-step__head {
  border-color: #1a1e3a;
  display: flex;
  align-items: center;
  font-weight: 400;
  color: #686E84;
}
.el-step.is-horizontal .el-step__line {
  height: 2px;
  top: 11px;
  left: 12px;
  right: 12px;
  background-color: #2ED47A;
}
.step-title {
  background-color: #fff;
  position: relative;
  z-index: 1;
  padding-left: 5px;
  padding-right: 5px;
}
.is-process {
  .el-step__icon.is-text {
    border: 2px solid #008BEE;
    background-color: #008BEE;
    color: #fff;
  }
  .step-title {
    font-weight: 600;
    color: #303753;
  }
}
</style>
